<!DOCTYPE html>
<html lang="en">
<head>
	<meta charset="UTF-8">
	<title>WebSocket</title>
</head>
<body>
		<h1>WebSocket 测试</h1>
		<input id="sendTxt" type="text">
    <button id="sendBtn">发送</button>
		<div id="recv"></div>
		<script>
			var websocket=new WebSocket('ws://localhost:8001/');
			websocket.onopen=function () {
				console.log('websocket open');
				document.getElementById('recv').innerHTML='connect';
					document.getElementById('sendBtn').onclick=function () {
					var val=document.getElementById('sendTxt').value;
					websocket.send(val);
	      }
      }
      websocket.onclose=function () {
				console.log('websocket close')
        var div=document.createElement("DIV");

        document.getElementById('recv').appendChild(div)
				div.innerHTML='close'

      }

      websocket.onmessage=function (e) {
				console.log(e.data);
        var div=document.createElement("DIV");
        document.getElementById('recv').appendChild(div)
        div.innerHTML=e.data
      }

      
		</script>
</body>
</html>